<?php 	
  $activeSeasonId = intval($sf_user->getAttribute('activeSeasonId'));
  $matchdayId = $activeSeasonId ? Doctrine::getTable('BbMatchday')->getMatchdayId($activeSeasonId) : 0;
  $matches = Doctrine::getTable('BbMatch')->getMatches(6, $matchdayId);
?>
<div id="scoreboard">
  	<ul>
  		<li><a href="#tabs-1">Sprite Дээд Лиг</a></li>
  		<li><a href="#tabs-2">Sprite Хөгжлийн Лиг</a></li>
  	</ul>
  	<div id="tabs-1">
    	<table width="100%" cellspacing="0" cellpadding="0" border="0" class="record generic scoreboard">
    		<tr> 
    			<td valign="middle" align="center">
    			<h6><?php echo $matchdays ?></h6>    			
    			</td>
    		</tr>    			
    
    <?php foreach ($matches as $match):		  
		    $team1 = $match->getBbTeams();
		    $team2 = $match->getBbTeams_2();    			      
    		if($match->published == 1 ) { 
    		if($match->m_played == 1) { ?>
      	    <tr>
      				<td>
      					<table width="100%" cellspacing="0" cellpadding="0" border="0">
      						<tbody>
      							<tr>
      								<td width="0%" valign="middle"><?php echo image_tag('/uploads/team/'.$team1->getTEmblem(), array('alt'=>$team1))?></td>
      								<td width="40%" align="center" valign="middle"><h5><?php echo $team1?></h5><?php echo $match->getScore1()?></td>
      								<td valign="middle" align="center">&nbsp;vs&nbsp;</td>
      								<td width="40%" align="center" valign="middle"><h5><?php echo $team2?></h5><?php echo $match->getScore2()?></td>
      								<td width="0%" valign="middle"><?php echo image_tag('/uploads/team/'.$team2->getTEmblem(), array('alt'=>$team2))?></td>
      							</tr>
      						</tbody>
      					</table>
      				</td>
      			</tr>
      			<tr>
      				<td colspan="6">
      					</br>
      					<hr style="border:0;border-top:1px dotted #eee;"/>
      				</td>
      			</tr>
      		<?php 
    			} 
    			else
    			{ ?>
    				
    			 <tr>
      				<td>
      					<table width="100%" cellspacing="0" cellpadding="0" border="0">
      						<tbody>
      							<tr>
      								<td width="0%" valign="middle"><?php echo image_tag('/uploads/team/'.$team1->getTEmblem(), array('alt'=>$team1))?></td>
      								<td width="40%" align="center" valign="middle"><h5><?php echo $team1?></h5>
      								<td valign="middle">&nbsp;VS&nbsp;</td>      								
      								<td width="40%" align="center" valign="middle"><h5><?php echo $team2?></h5>
      								<td width="0%" valign="middle"><?php echo image_tag('/uploads/team/'.$team2->getTEmblem(), array('alt'=>$team2))?></td>
      							</tr>
      						</tbody>
      					</table>
      				</td>
      			</tr>
      			<tr>
      				<td  align="center"><?php echo $match->getMLocation() ?></td>      				
      			</tr>
      			<tr>
					<td align="center"><?php echo substr($match->getMDate() , 11, 5)?> цагт</td>      				      				
      			</tr>      			      		
      			<tr>
      				<td colspan="6">
      					<hr style="border:0;border-top:1px dotted #eee;"/>
      				</td>
      			</tr>	
    					
			<?php    					
    			}
    	}
    		?>
      		
      	  <?php endforeach ?>
  		</table>
  	</div>

  	<?php 
	$matchday_id = Doctrine::getTable('BbMatchday')->getMatchday(3)->getId();
	$matches = Doctrine::getTable('BbMatch')->getMatches(6, $matchday_id);
?>

  	<div id="tabs-2">
  		<table width="100%" cellspacing="0" cellpadding="0" border="0" class="record generic scoreboard">
    		<tr> 
    			<td valign="middle" align="center">
    			<h6><?php echo $matchdays ?></h6>    			
    			</td>
    		</tr>  
  		<?php foreach ($matches as $match):		  
		    $team1 = $match->getBbTeams();
		    $team2 = $match->getBbTeams_2();    			      
    		if($match->published == 1 ) { 
    		if($match->m_played == 1) { ?>
      	    <tr>
      				<td>
      					<table width="100%" cellspacing="0" cellpadding="0" border="0">
      						<tbody>
      							<tr>
      								<td width="0%" valign="middle"><?php echo image_tag('/uploads/team/'.$team1->getTEmblem(), array('alt'=>$team1))?></td>
      								<td width="40%" align="center" valign="middle"><h5><?php echo $team1?></h5><?php echo $match->getScore1()?></td>
      								<td valign="middle" align="center">&nbsp;vs&nbsp;</td>
      								<td width="40%" align="center" valign="middle"><h5><?php echo $team2?></h5><?php echo $match->getScore2()?></td>
      								<td width="0%" valign="middle"><?php echo image_tag('/uploads/team/'.$team2->getTEmblem(), array('alt'=>$team2))?></td>
      							</tr>
      						</tbody>
      					</table>
      				</td>
      			</tr>
      			<tr>
      				<td colspan="6">
      					</br>
      					<hr style="border:0;border-top:1px dotted #eee;"/>
      				</td>
      			</tr>
      		<?php 
    			} 
    			else
    			{ ?>
    				
    			 <tr>
      				<td>
      					<table width="100%" cellspacing="0" cellpadding="0" border="0">
      						<tbody>
      							<tr>
      								<td width="0%" valign="middle"><?php echo image_tag('/uploads/team/'.$team1->getTEmblem(), array('alt'=>$team1))?></td>
      								<td width="40%" align="center" valign="middle"><h5><?php echo $team1?></h5>
      								<td valign="middle">&nbsp;VS&nbsp;</td>      								
      								<td width="40%" align="center" valign="middle"><h5><?php echo $team2?></h5>
      								<td width="0%" valign="middle"><?php echo image_tag('/uploads/team/'.$team2->getTEmblem(), array('alt'=>$team2))?></td>
      							</tr>
      						</tbody>
      					</table>
      				</td>
      			</tr>
      			<tr>
      				<td  align="center"><?php echo $match->getMLocation() ?></td>      				
      			</tr>
      			<tr>
      				<td align="center"><?php echo substr($match->getMDate() , 11, 5)?> цагт</td>      				      				
      			</tr>      			      		
      			<tr>
      				<td colspan="6">
      					<hr style="border:0;border-top:1px dotted #eee;"/>
      				</td>
      			</tr>	
    					
			<?php    					
    			}
    	}
    		?>
      		
      	  <?php endforeach ?>
  		</table>
  	</div>  	
</div>

<br clear="all">

<script type="text/javascript">
$(function() {
	$("#scoreboard").tabs();
});
</script>